/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs575.dbentities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author bms
 */
@Entity
@Table(name = "task", catalog = "tasks_management", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Task.findAll", query = "SELECT t FROM Task t"),
    @NamedQuery(name = "Task.findByTaskId", query = "SELECT t FROM Task t WHERE t.taskId = :taskId"),
    @NamedQuery(name = "Task.findByTaskName", query = "SELECT t FROM Task t WHERE t.taskName = :taskName"),
    @NamedQuery(name = "Task.findByDueDate", query = "SELECT t FROM Task t WHERE t.dueDate = :dueDate"),
    @NamedQuery(name = "Task.findByStatus", query = "SELECT t FROM Task t WHERE t.status = :status")})
public class Task implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "task", fetch = FetchType.LAZY)
    private List<TaskAssign> taskAssignList;
    public static final int Active = 1;
    public static final int Completed = 2;
    private static final long serialVersionUID = 1L;
    @TableGenerator(name="Task_Gen", table="ID_GEN", pkColumnName="GEN_NAME", valueColumnName="GEN_VAL")
    @Id @GeneratedValue(generator="Task_Gen")    
    @Basic(optional = false)
    @Column(name = "task_id", nullable = false)
    private Integer taskId;
    @Basic(optional = false)
    @Column(name = "task_name", nullable = false, length = 100)
    private String taskName;
    @Basic(optional = false)
    @Lob
    @Column(name = "task_description", nullable = false, length = 65535)
    private String taskDescription;
    @Basic(optional = false)
    @Column(name = "due_date", nullable = false, length = 100)
    private String dueDate;
    @Basic(optional = false)
    @Column(name = "status", nullable = false)
    private int status;
    @OneToMany(mappedBy = "parentId", fetch = FetchType.LAZY)
    private List<Task> taskList;
    @JoinColumn(name = "parent_id", referencedColumnName = "task_id")
    @ManyToOne(fetch = FetchType.LAZY)
    private Task parentId;
    @JoinColumn(name = "group_id", referencedColumnName = "group_id", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private GroupEx groupId;

    public Task() {
    }

    public Task(Integer taskId) {
        this.taskId = taskId;
    }

    public Task(String taskName, String taskDescription, String dueDate, int status,GroupEx group) {
        this.taskName = taskName;
        this.taskDescription = taskDescription;
        this.dueDate = dueDate;
        this.status = status;
        this.groupId = group;
    }

    public Integer getTaskId() {
        return taskId;
    }

    public void setTaskId(Integer taskId) {
        this.taskId = taskId;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public String getTaskDescription() {
        return taskDescription;
    }

    public void setTaskDescription(String taskDescription) {
        this.taskDescription = taskDescription;
    }

    public String getDueDate() {
        return dueDate;
    }

    public void setDueDate(String dueDate) {
        this.dueDate = dueDate;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @XmlTransient
    public List<Task> getTaskList() {
        return taskList;
    }

    public void setTaskList(List<Task> taskList) {
        this.taskList = taskList;
    }

    public Task getParentId() {
        return parentId;
    }

    public void setParentId(Task parentId) {
        this.parentId = parentId;
    }

    public GroupEx getGroupId() {
        return groupId;
    }

    public void setGroupId(GroupEx groupId) {
        this.groupId = groupId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (taskId != null ? taskId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Task)) {
            return false;
        }
        Task other = (Task) object;
        if ((this.taskId == null && other.taskId != null) || (this.taskId != null && !this.taskId.equals(other.taskId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cs575.dbentities.Task[ taskId=" + taskId + " ]";
    }

    @XmlTransient
    public List<TaskAssign> getTaskAssignList() {
        return taskAssignList;
    }

    public void setTaskAssignList(List<TaskAssign> taskAssignList) {
        this.taskAssignList = taskAssignList;
    }
    
}
